<?php
/**
 * MongoDig
 *
 * @copyright  Copyright (c) 2010 lanyanguang (http://www.lanyg.com)
 * @license    GNU General Public License 2.0
 * @version    $Id$
 */

/** topic逻辑操作 */

//插入一个主题
function topic_insert($topic)
{
	global $db;
	$collection = $db->topic;
	$collection->insert($topic);
}

//批量添加主题
function topic_insert_patch($topics)
{
	global $db;
	$collection = $db->topic;
	$collection->batchInsert($topics);
}

//删除一个主题
function topic_delete($filter)
{
	global $db;
	$collection = $db->topic;
	$collection->remove($filter);
}

//更新一个主题信息
function topic_update($filter,$topic)
{
	global $db;
	$collection = $db->topic;
	$collection->update($filter,$topic);
}

//查找一个主题信息
function topic_find_one($filter)
{
	global $db;
	$collection = $db->topic;
	return $topic = $collection->findOne($filter);
}

//查找主题信息
function topic_find($filter='')
{
	global $db;
	$collection = $db->topic;
	if(empty($filter)){
		return $topic = $collection->find();
	}else{
		return $topic = $collection->find($filter);
	}
}